class Clock extends React.Component {
    constructor(props) {
        super(props);
        this.state = { date: new Date() };
    }

    componentDidMount() {
        this.timerID = setInterval(() => this.tick(), this.props.interval || 1000);
    }

    componentWillUnmount() {
        clearInterval(this.timerID);
    }

    tick() {
        this.setState({
            date: new Date()
        });
    }

    render() {
        return (
            <section>
                <h1>Hello, React</h1>
                <h2>It is {this.state.date.toLocaleDateString() + ' ' + this.state.date.toLocaleTimeString()}.</h2>
            </section>
        );
    }
}

export default Clock;